package com.yager.controller;

import com.yager.model.Admin;
import com.yager.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 12866
 * @version 1.0
 * @date 2021/11/18 9:47
 */
@Controller
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/test/insert/{id}/{name}/{password}")
    public @ResponseBody
    Object InsertOneAdmin(@PathVariable("id") String id,
                          @PathVariable("name") String name,
                          @PathVariable("password") String password) {
        Admin admin = new Admin(id, name, password);
        adminService.InsertOneAdmin(admin);
        return "已经成功插入一条学生信息！！！" + admin;
    }

    /*那这个是成功完成了放和拿的一个例子，注意序列化的时候被序列化的类一定要有无參构造。*/
    @RequestMapping("/test/redis/getAllAdmin")
    public @ResponseBody
    Object getAllAdmin() {
        List<Admin> list = adminService.getAllAdmin();
        return list;
    }

    @RequestMapping("/admin/info")
    public String info(){
        return "admins/info";
    }

    @RequestMapping("/admin/login")
    public String login(){
        return "admins/login";
    }

}
